package com.hamizhong.iflowers.web.action.admin.prodgoods;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.hamizhong.iflowers.service.IFestivalService;
import com.hamizhong.iflowers.service.IFlowerCountService;
import com.hamizhong.iflowers.service.IFlowerFloridService;
import com.hamizhong.iflowers.service.IGoodsFestivalMapService;
import com.hamizhong.iflowers.service.IGoodsProductMapService;
import com.hamizhong.iflowers.service.IGoodsPurposeMapService;
import com.hamizhong.iflowers.service.IGoodsService;
import com.hamizhong.iflowers.service.IGoodsTargetMapService;
import com.hamizhong.iflowers.service.IProductService;
import com.hamizhong.iflowers.service.IPurposeService;
import com.hamizhong.iflowers.service.ITargetService;
import com.hamizhong.iflowers.utils.MyColumnIndicator;
import com.hamizhong.iflowers.utils.MyConstants;
import com.hamizhong.iflowers.utils.MyTools;
import com.hamizhong.iflowers.web.base.MyBaseAjaxAction;
import com.hamizhong.iflowers.web.dto.IOPResultDto;
import com.hamizhong.iflowers.web.vo.GoodsVO;
import com.hamizhong.iflowers.web.vo.IObjectVO;

public class AjaxUpdateGoodsBarginStateAction extends MyBaseAjaxAction {
	private IGoodsService iGoodsService = null;
	private IProductService iProductService = null;
	private IPurposeService iPurposeService = null;
	private IFestivalService iFestivalService = null;
	private ITargetService iTargetService = null;
	private IFlowerFloridService iFlowerFloridService = null;
	private IFlowerCountService iFlowerCountService = null;
	private IGoodsProductMapService iGoodsProductMapService = null;
	private IGoodsPurposeMapService iGoodsPurposeMapService = null;
	private IGoodsFestivalMapService iGoodsFestivalMapService = null;
	private IGoodsTargetMapService iGoodsTargetMapService = null;
	
	public IGoodsService getiGoodsService() {
		return iGoodsService;
	}
	public void setiGoodsService(IGoodsService iGoodsService) {
		this.iGoodsService = iGoodsService;
	}
	public IProductService getiProductService() {
		return iProductService;
	}
	public void setiProductService(IProductService iProductService) {
		this.iProductService = iProductService;
	}
	public IPurposeService getiPurposeService() {
		return iPurposeService;
	}
	public void setiPurposeService(IPurposeService iPurposeService) {
		this.iPurposeService = iPurposeService;
	}
	public IFestivalService getiFestivalService() {
		return iFestivalService;
	}
	public void setiFestivalService(IFestivalService iFestivalService) {
		this.iFestivalService = iFestivalService;
	}
	public ITargetService getiTargetService() {
		return iTargetService;
	}
	public void setiTargetService(ITargetService iTargetService) {
		this.iTargetService = iTargetService;
	}
	public IFlowerFloridService getiFlowerFloridService() {
		return iFlowerFloridService;
	}
	public void setiFlowerFloridService(IFlowerFloridService iFlowerFloridService) {
		this.iFlowerFloridService = iFlowerFloridService;
	}
	public IFlowerCountService getiFlowerCountService() {
		return iFlowerCountService;
	}
	public void setiFlowerCountService(IFlowerCountService iFlowerCountService) {
		this.iFlowerCountService = iFlowerCountService;
	}
	public IGoodsProductMapService getiGoodsProductMapService() {
		return iGoodsProductMapService;
	}
	public void setiGoodsProductMapService(
			IGoodsProductMapService iGoodsProductMapService) {
		this.iGoodsProductMapService = iGoodsProductMapService;
	}
	public IGoodsPurposeMapService getiGoodsPurposeMapService() {
		return iGoodsPurposeMapService;
	}
	public void setiGoodsPurposeMapService(
			IGoodsPurposeMapService iGoodsPurposeMapService) {
		this.iGoodsPurposeMapService = iGoodsPurposeMapService;
	}
	public IGoodsFestivalMapService getiGoodsFestivalMapService() {
		return iGoodsFestivalMapService;
	}
	public void setiGoodsFestivalMapService(
			IGoodsFestivalMapService iGoodsFestivalMapService) {
		this.iGoodsFestivalMapService = iGoodsFestivalMapService;
	}
	public IGoodsTargetMapService getiGoodsTargetMapService() {
		return iGoodsTargetMapService;
	}
	public void setiGoodsTargetMapService(
			IGoodsTargetMapService iGoodsTargetMapService) {
		this.iGoodsTargetMapService = iGoodsTargetMapService;
	}
	
	@Override
	protected JSONObject doRequest() {
		String goodsId = getRQ().getParameter("goodsId");
		String isBargin = getRQ().getParameter("isBargin");
		String barginPrice = getRQ().getParameter("barginPrice");
		JSONObject jo = new JSONObject();
		GoodsVO goodsVO = new GoodsVO();
		goodsVO.setGoodsId(Integer.valueOf(goodsId));
		goodsVO.setIsBargin(Integer.valueOf(isBargin));
		if(Integer.valueOf(isBargin) == MyColumnIndicator.G_BARGIN_ST_A0) {
			goodsVO.setBarginPrice(new Float(-1));
		}else if(Integer.valueOf(isBargin) == MyColumnIndicator.G_BARGIN_ST_B1) {
			goodsVO.setBarginPrice(new Float(barginPrice));
		}
		IOPResultDto<IObjectVO> dto = iGoodsService.updateGoodsBarginState(goodsVO);
		if(dto.isSuccess()) {
			jo.put("result", MyConstants.AJAX_SUCCESS);
		}else {
			jo.put("result", MyConstants.AJAX_FAILED_ALERT);
			jo.put("msg", dto.getErrorMSG());
		}
		return jo;
	}

}
